import axios from 'axios'
import envFuncs from '@/config/base'
let env = envFuncs.getParams()
import store from '../../store'
import Q from 'q'

export const channelOptions = {
  text: '客户渠道',
  name: 'channel_id',
  class: 'txt-center',
  value: 'channel_id',
  showSearch: true,
  checked: '',
  options: []
}

export const getChannelOptions = () => {
  const token = store.state.app.token
  const CRM_API_HOST = env.CRM_API_HOST
  return Q.Promise((resolve) => {
    axios.get(CRM_API_HOST + '/users/' + token + '/channels')
    .then((response) => {
      if (response.data.errcode === 0) {
        const channels = response.data.results
        const options = [{text: '不限', value: '-1'}]
        console.log(channels, 'channels')
        channels.forEach((channel, index) => {
          options.push({ text: channel.channel_name, value: channel.channel_id })
        })
        channelOptions.options = options
        resolve(channelOptions)
      }
    })
  })
}
